package com.serli.sample.person.model.data.persistence;

import com.serli.sample.person.model.data.Gender;
import com.serli.sample.person.model.data.Person;
import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import java.util.Date;
import javax.persistence.*;

/**
 * Class contenant les données d'une personne. Cette classe est une entité
 * persistante de type JPA 2.0.</br> <b>Modèle de la table :</b>
 * <pre>
 * +-----------------------------+
 * |          PERSONNE           |
 * +-----------------------------+
 * | ID             <bigint>     |
 * | PRENOM         <varchar 32> |
 * | NOM            <varchar 32> |
 * | DATE_NAISSANCE <date>       |
 * | SEXE           <integer>    |
 * +-----------------------------+
 * </pre>
 *
 * @author Pascal MERON
 */
@Entity
@Table(name = "PERSONNE")
@NamedQueries({
    @NamedQuery(name = PersonEntity.QUERY_FIND_ALL_ORDER_BY_FIRSTNAME, query = "SELECT OBJECT(p) FROM PersonEntity p ORDER BY p.firstName")
})
public class PersonEntity implements Serializable {

    public static final String QUERY_FIND_ALL_ORDER_BY_FIRSTNAME = "findAllOrderByFirstName";

    private static final long serialVersionUID = 8847687019433337777L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private int id=-1;
   
    @Basic
    @Column(name = "PRENOM", length = 32, nullable = false)
    private String firstName = null;
    
    @Basic
    @Column(name = "NOM", length = 32, nullable = false)
    private String lastName = null;
    
    @Temporal(TemporalType.DATE)
    @Column(name = "DATE_NAISSANCE")
    private Calendar birthDate = null;
   
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "SEXE")
    private Gender gender = Gender.MALE;

    public PersonEntity() {
    }
   
    public PersonEntity(Person p) {
        this(p.getId(), p.getFirstName(), p.getLastName(), p.getBirthDate(), p.getGender());
    }

    public PersonEntity(int id, String firstName, String lastName, Calendar birthDate, Gender gender) {
        super();
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.birthDate = birthDate;
        this.gender = gender;
    }
    
    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    
    public String getLastName() {
        return this.lastName;
    }
    
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    
    public Calendar getBirthDate() {
        return this.birthDate;
    }
    
    public void setBirthDate(Calendar birthDate) {
        this.birthDate = birthDate;
    }
    
    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }
   
    @Override
    public String toString() {
        return "PersonEntity [id=" + getId() + ", firstName=" + firstName + ", lastName="
                + lastName + ", birthDate=" + birthDate + ", gender=" + gender
                + "]";
    }
}